﻿//-----------------------------------------------------------------------
// <copyright file="UserPrincipal.cs">
//     Copyright (c) Wolf166 - BGF Framework
// </copyright>
// <Autor>Wolf166 - BGF Framework</Autor>
//-----------------------------------------------------------------------
namespace BrowserGameFramework.Account
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Security.Principal;
    using System.Security;

    /// <summary>
    /// This Object represens the current user
    /// </summary>
    [Serializable]
    public class UserPrincipal : IUserprincipal
    {
        #region props

        /// <summary>
        /// Gets or sets the UserID.
        /// </summary>
        /// <value>The ID of this user/value>
        public int ID { get; set; }

        /// <summary>
        /// Gets or sets the ingame username like Robi482
        /// </summary>
        /// <value>The name of this user</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the name of the loginName
        /// </summary>
        /// <value>The name of the login.</value>
        public string LoginName { get; set; }

        /// <summary>
        /// Gets or sets the email.
        /// </summary>
        /// <value>The email.</value>
        public string Email { get; set; }

        /// <summary>
        /// All Roles of this user
        /// </summary>
        private string[] roles;

        /// <summary>
        /// Gets or sets the Alliance/Group id.
        /// </summary>
        /// <value>The alliance/group id.</value>
        public List<GameGroup> Groups { get; set; }

        #endregion props

        #region methods

        public UserPrincipal()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UserPrincipal"/> class.
        /// </summary>
        public UserPrincipal(string[] roles)
        {
            this.roles = roles;
        }

        /// <summary>
        /// Checks the Grouplist
        /// </summary>
        /// <param name="id">Group ID</param>
        /// <returns>True or False</returns>
        public bool IsInGroup(int id)
        {
            int cnt = Groups.Count(i => i.GroupId == id);

            if (cnt != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Check if the user has the role
        /// </summary>
        /// <param name="role">The name of Role</param>
        /// <returns>
        /// true, if the User has the role - false, if not
        /// </returns>
        public bool IsInRole(string role)
        {
            int cnt = roles.Count(i => i == role);

            if (cnt != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion methods
    }

}
